package net.maku.module.organization.controller;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.constant.Constant;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.framework.common.utils.TreeUtils;
import net.maku.module.organization.convert.OrganizationConvert;
import net.maku.module.organization.convert.PositionTypeConvert;
import net.maku.module.organization.entity.OrganizationEntity;
import net.maku.module.organization.entity.PositionTypeEntity;
import net.maku.module.organization.service.PositionTypeService;
import net.maku.module.organization.vo.PositionTypeVO;
import net.maku.newbase.NewBaseController;
import net.maku.newbase.NewQuery;
import net.maku.newbase.PageParam;

import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
* 业务_职位类别
*
* @author    
*/
@RestController
@RequestMapping("nb/position_type")
@Tag(name="业务_职位类别")
@AllArgsConstructor
public class PositionTypeController extends NewBaseController<PositionTypeService, PositionTypeEntity> {

    @GetMapping("page")
    @Operation(summary = "分页")
    public Result<PageResult<PositionTypeVO>> page(PageParam page, NewQuery query){
        LambdaQueryWrapper<PositionTypeEntity> select = new LambdaQueryWrapper<>();

        IPage<PositionTypeEntity> iPage = entityService.page(page.b(), select);
        return Result.ok(new PageResult<>(PositionTypeConvert.INSTANCE.convertList(iPage.getRecords()), iPage.getTotal()));

    }

    /**
     * 查询 列表
     *
     * @return
     */
    @Operation(summary = "全部")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result list() {
        List<PositionTypeEntity> list = entityService.list();

        return Result.ok(TreeUtils.build(PositionTypeConvert.INSTANCE.convertList(list), Constant.ROOT));
    }

}